<%@page import="com.bionic.banking.logic.controller.CustomerController"%>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        
        <link rel="stylesheet" href="../resources/css/demos.css">               
        <link rel="stylesheet" href="../resources/themes/cupertino/jquery-ui.css" />                    

        <script type="text/javascript" src="../resources/script/jquery.min.js"></script>
        <script type="text/javascript" src="../resources/script/ui/jquery-ui.min.js"></script>   
        
        <title>List Of Persons</title>        
        <script type="text/javascript" >                    
            function editRecord(id)
            {
                var f=document.forms[0];                                
                f.method="post";                                
                //f.action='../customer/Edit.jsp?id='+id;                                
                f.action='Controller?command=startEditCustomer&id='+id;
                f.submit();
            }
                    
            function deleteRecord(id)
            {                          
                var result = confirm('Are you sure to remove the customer ?')
                if(result == 1)
                {        
                    var f=document.forms[0];                             
                    f.method="post";
                    f.action='../customer/Delete.jsp?id='+id;//TODO:
                    f.submit();
                }
            }
        </script>
    </head>
    <body>
        <h3>Customers List</h3>

        <jsp:useBean id="domainHelperBean" scope="page"
                     class="com.bionic.banking.logic.DomainUtil" />
        <jsp:useBean id="customerBean" scope="page"
                     class="com.bionic.banking.logic.controller.CustomerController" />   
        <form action="../Controller" method="post">
            <table id="tblList" border="3" >                
                  <tr>    
                    <th bgcolor=silver>First name</th>
                    <th bgcolor=silver>Last name</th>
                    <th bgcolor=silver>Middle name</th>
                    <th bgcolor=silver>Age</th>
                    <th bgcolor=silver>Gender</th>
                    <th bgcolor=silver>Phone</th>
                    <th bgcolor=silver>Fax</th>
                    <th bgcolor=silver >Email</th>
                    <th bgcolor=silver >Image</th>
                    <th bgcolor=silver />
                    <th bgcolor=silver />
                  </tr>
                    <c:set var="items" scope="page" value="${customerBean.getAll()}"/>
                    <c:set var="start" scope="session" value="1"/>  
                     <c:set var="chunkSize" scope="page" value="5"/>
                    <c:set var="totalSize" scope="page" value="50"/>                    
                    <c:if test="${param.start>0}" >
                        <c:set var="start" scope="page" value="${param.start}"/>
                    </c:if>
                    
                    <c:forEach var="customer" begin="${start}" end="${start+chunkSize-1}"
                               items="${items}">
                        <tr>
                            <td>${customer.firstName}&nbsp;&nbsp;</td>
                            <td>${customer.lastName}&nbsp;&nbsp;</td>
                            <td>${customer.middleName}&nbsp;&nbsp;</td>
                            <td>${customer.age}&nbsp;&nbsp;</td>
                            <td>${domainHelperBean.getGenderSignature(customer.gender)}</td>
                            <td>${customer.phone}&nbsp;&nbsp;</td>
                            <td>${customer.fax}&nbsp;&nbsp;</td>
                            <td>${customer.email}&nbsp;&nbsp;</td>       
                            <td><img src='../ImageServlet?customerId=${customer.customerId}'
                                     width="50" height="50" />
                                &nbsp;&nbsp;
                            </td>     
                            <td><a href="javascript:editRecord(${customer.customerId});" >
                                    Edit
                                </a>
                            </td> 
                            <td><a href="javascript:deleteRecord(${customer.customerId});">
                                    Delete
                                </a>
                            </td>
                        </tr>
                    </c:forEach>    
                    
                    <c:forEach var="i" begin="1" end="${totalSize - 1}" step="${chunkSize}">
                          <a href="?command=viewCustomersList&start=<c:out value="${i}"/>" >
                             <b>
                               (<c:out value="${i}"/>-<c:out value="${i + chunkSize - 1}"/>)
                             </b>
                         </a>
                    </c:forEach>

                </table>
            <br/>
            <a href="Controller?command=startCreateCustomer"><strong>Register a new Customer</strong></a>
        </form>
    </body>
</html>
